﻿/*
 *
 * User: inffbr
 * Date: 17.02.2011
 * Time: 09:33
 * 
 */
using System;
using System.Collections.Generic;
using ThatsMeSDK;
using ThatsMeSDK.Core;

namespace SDKTest
{
	/// <summary>
	/// Description of KernelTestFuncs.
	/// </summary>
	public static class KernelTestFuncs
	{
		public static void LoadMemberByNickTest()
		{
			Member m = (Member)ThatsMeSDK.Core.ServiceHandler.GetMemberByNick("tmdotnetapi");
			Console.WriteLine(m.Id.ToString());
		}
		
		public static void LoadMemberByIdTest()
		{
			Member m = (Member)ThatsMeSDK.Core.ServiceHandler.GetMemberById(179);
			Console.WriteLine(m.Nick);
		}

        public static  void TestDashBoard()
        {
            Dashboard dashboard = new Dashboard();
            if (dashboard != null)
                Console.WriteLine("Dashboard loaded successfully");
        }

	    public static string AuthenticateUserTest()
		{
			string username = "tmdotnetapi";
			string password = "nexpose";
			
			string passwordhash = ThatsMeSDK.Core.ServiceHandler.CalculateMD5(password);
			
			string token = ThatsMeSDK.Core.ServiceHandler.Authenticate(username, passwordhash);
			
			return token;
		}
		
		public static void CountMessagesTest()
		{
			string token = AuthenticateUserTest();
			
			if (token != null)
			{
				MessageCount msgcount = ThatsMeSDK.Core.ServiceHandler.CountMessages(token);
				Console.WriteLine("You have " + msgcount.Unread.Total + " unread messages!");
			}
		}
		
		public static void LoadMessageTest()
		{
			string token = AuthenticateUserTest();
			Message myloadedmessage = ThatsMeSDK.Core.ServiceHandler.GetMessage(5984141, token);
			
			Console.WriteLine(myloadedmessage.Header.Subject);
		}
		
		public static void LoadMessagesTest()
		{
			string token = AuthenticateUserTest();
			List<Message> myloadedmessages = ThatsMeSDK.Core.ServiceHandler.GetMessages(token, 0, 10, MessageType.Messages, false);
			
			Console.WriteLine(myloadedmessages[0].Header.Subject);
		}
		
		public static void LoadPicturesTest()
		{
			List<GalleryPicture> pics = ServiceHandler.GetNewPics(10);
			
			foreach(GalleryPicture pic in pics)
			{
				Console.WriteLine(pic.Url);
			}
		}
		
		public static void JsonDataLoaderTest()
		{
			ThatsMeSDK.Core.ServiceHandler.Initialize(DataFormat.Json);
			LoadMemberByIdTest();
		}
		
		public static void SendMessageTest()
		{
			string token = AuthenticateUserTest();
			
			bool retval = ServiceHandler.SendMessage(token, "test message vom API", "InTheAir", "test message");
		}
		  
		public static void GetGalleryCategoriesTest()
		{
			List<GalleryCategory> categories = ServiceHandler.GetUserPicCategories("broox");
		}
		
		public static void GetGalleryPicturesTest()
		{
			List<GalleryPicture> pictures = ServiceHandler.GetUserPics("broox");
		}		
		                              
	}
}
